<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>NativeBridge 简单测试</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        button { padding: 10px 20px; margin: 10px; font-size: 16px; }
        #log { background: #f0f0f0; padding: 10px; margin-top: 20px; height: 200px; overflow-y: auto; }
    </style>
</head>
<body>
    <h1>NativeBridge 简单测试</h1>
    
    <button onclick="testNativeBridge()">测试 NativeBridge</button>
    <button onclick="testNavigateBack()">测试返回</button>
    <button onclick="checkNativeBridge()">检查 NativeBridge</button>
    
    <div id="log"></div>
    
    <script>
        function log(message) {
            const logDiv = document.getElementById('log');
            const time = new Date().toLocaleTimeString();
            logDiv.innerHTML += `[${time}] ${message}<br>`;
            logDiv.scrollTop = logDiv.scrollHeight;
        }
        
        function checkNativeBridge() {
            log('检查 NativeBridge 对象...');
            if (typeof NativeBridge !== 'undefined') {
                log('✅ NativeBridge 对象存在');
                log('NativeBridge 类型: ' + typeof NativeBridge);
                if (typeof NativeBridge.postMessage === 'function') {
                    log('✅ NativeBridge.postMessage 方法存在');
                } else {
                    log('❌ NativeBridge.postMessage 方法不存在');
                }
            } else {
                log('❌ NativeBridge 对象不存在');
            }
            
            if (typeof window.flutter_inappwebview !== 'undefined') {
                log('✅ flutter_inappwebview 对象存在');
            } else {
                log('❌ flutter_inappwebview 对象不存在');
            }
        }
        
        function testNativeBridge() {
            log('测试 NativeBridge.postMessage...');
            if (typeof NativeBridge !== 'undefined') {
                const testMessage = {
                    action: 'navigateBack',
                    webview: 'zWebView'
                };
                log('发送测试消息: ' + JSON.stringify(testMessage));
                NativeBridge.postMessage(JSON.stringify(testMessage));
            } else {
                log('❌ NativeBridge 不可用');
            }
        }
        
        function testNavigateBack() {
            log('测试返回操作...');
            if (typeof NativeBridge !== 'undefined') {
                const message = {
                    action: 'navigateBack',
                    webview: 'zWebView'
                };
                log('发送返回命令: ' + JSON.stringify(message));
                NativeBridge.postMessage(JSON.stringify(message));
            } else {
                log('❌ NativeBridge 不可用');
            }
        }
        
        // 页面加载完成后自动检查
        document.addEventListener('DOMContentLoaded', function() {
            log('页面加载完成');
            setTimeout(checkNativeBridge, 1000);
        });
        
        // 监听来自Flutter的消息
        if (typeof window !== 'undefined') {
            window.flutterMessageHandler = function(message) {
                log('收到Flutter消息: ' + message);
            };
        }
    </script>
</body>
</html> 